package com.htgd.gardenexpo.controller;


import com.alibaba.fastjson.JSONObject;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConFood;
import com.htgd.gardenexpo.entity.GeConFoodShop;
import com.htgd.gardenexpo.page.FoodShopQuery;
import com.htgd.gardenexpo.service.IGeConFoodShopService;
import com.htgd.gardenexpo.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 * 美食店铺表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-13
 */
@RestController
@RequestMapping("/api/foodShop")
@Api(tags = "美食店铺")
@Slf4j
public class GeConFoodShopController {
    @Autowired
    private IGeConFoodShopService geConFoodShopService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConFoodShop geConFoodShop){
            log.info("美食店铺-添加：{}",geConFoodShop);
            return geConFoodShopService.add(geConFoodShop);
    }

    @PostMapping("/edit")
    @ApiOperation("编辑")
    public CommonResult edit(@RequestBody GeConFoodShop geConFoodShop){
        log.info("美食店铺-编辑：{}",geConFoodShop);
        return geConFoodShopService.edit(geConFoodShop);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除")
    public CommonResult delete(@RequestParam(value = "id")String id){
        log.info("美食店铺-删除：{}",id);
        return geConFoodShopService.delete(id);
    }

    @GetMapping("/list")
    @ApiOperation("列表查询")
    public CommonResult list(FoodShopQuery foodShopQuery, HttpServletRequest request){
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("美食店铺-列表查询：{},{}",openId,foodShopQuery);
        return geConFoodShopService.pageList(openId,foodShopQuery);
    }


    @GetMapping("/details")
    @ApiOperation("详情")
    public CommonResult details(@RequestParam(value = "id")String id,HttpServletRequest request){
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("美食店铺-详情：{},{}",openId,id);
        return geConFoodShopService.details(openId,id);
    }

    @GetMapping(value = "/review")
    @ApiOperation("审核")
    public CommonResult review(GeConFoodShop geConFoodShop) {
        log.info("美食店铺-审核：{}",geConFoodShop);
        return geConFoodShopService.review(geConFoodShop);
    }


    @GetMapping("/shopList")
    @ApiOperation("店铺")
    public CommonResult shopList(){
        log.info("美食店铺-店铺");
        return geConFoodShopService.shopList();
    }

}
